package com.sengled.cloud.biz.union.mgt.model.response;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.sengled.cloud.biz.union.mgt.common.ResponseConstants;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

/**
 * Created by ti on 2017/10/24.
 */
@Data
@JsonInclude(JsonInclude.Include.NON_NULL)
@ApiModel
public class ResponseMessage <T> {

    @ApiModelProperty(position = 1,value = "响应代码",required = true)
    private String messageCode = ResponseConstants.RSP_CODE_SUCCESS;

    @ApiModelProperty(position = 2,value = "响应信息",required = true)
    private String info = ResponseConstants.RSP_INFO_SUCCESS;

    @ApiModelProperty(position = 3,value = "响应描述",required = true)
    private String description = ResponseConstants.RSP_DESC_SUCCESS;

    @JsonIgnore
    private boolean success = true;

    @ApiModelProperty(position = 4,value = "业务数据对象")
    private T Data;

    public void buildSystemErrorMessage(){
        this.success = false;
        this.messageCode = ResponseConstants.RSP_CODE_SERVICE_ERROR;
        this.info = ResponseConstants.RSP_INFO_SERVICE_ERROR;
        this.description = ResponseConstants.RSP_DESC_SERVICE_ERROR;
    }

    public void buildParamErrorMessage(){
        this.success = false;
        this.messageCode = ResponseConstants.RSP_CODE_PARAM_LOST;
        this.info = ResponseConstants.RSP_INFO_PARAM_LOST;
        this.description = ResponseConstants.RSP_DESC_PARAM_LOST;
    }

    public void buildAuthErrorMessage(){
        this.success = false;
        this.messageCode = ResponseConstants.RSP_CODE_AUTH_ERROR;
        this.info = ResponseConstants.RSP_INFO_AUTH_ERROR;
        this.description = ResponseConstants.RSP_DESC_AUTH_ERROR;
    }

    public void buildExecuteFailMessage() {
        this.success = false;
        this.messageCode = ResponseConstants.RSP_CODE_EXECUTE_FAIL;
        this.info = ResponseConstants.RSP_INFO_EXECUTE_FAIL;
        this.description = ResponseConstants.RSP_DESC_EXECUTE_FAIL;
    }

    public void buildUploadFileFailMessage() {
        this.success = false;
        this.messageCode = ResponseConstants.RSP_CODE_UPLOADFILE_FAIL;
        this.info = ResponseConstants.RSP_INFO_UPLOADFILE_FAIL;
        this.description = ResponseConstants.RSP_DESC_UPLOADFILE_FAIL;
    }

    public void buildRoleCodeRepeatMessage() {
        this.success = false;
        this.messageCode = ResponseConstants.RSP_CODE_ROLE_CODE_REPEAT_FAIL;
        this.info = ResponseConstants.RSP_INFO_ROLE_CODE_REPEAT_FAIL;
        this.description = ResponseConstants.RSP_DESC_ROLE_CODE_REPEAT_FAIL;
    }

    public void buildUserUnLoginMessage() {
        this.success = false;
        this.messageCode = ResponseConstants.RSP_CODE_USER_UN_LOGIN_FAIL;
        this.info = ResponseConstants.RSP_INFO_USER_UN_LOGIN_FAIL;
        this.description = ResponseConstants.RSP_DESC_USER_UN_LOGIN_FAIL;
    }

    public void buildNoRoleLoginFalseMessage() {
        this.success = false;
        this.messageCode = ResponseConstants.RSP_CODE_NO_ROLE_LOGIN_FAIL;
        this.info = ResponseConstants.RSP_INFO_NO_ROLE_LOGIN_FAIL;
        this.description = ResponseConstants.RSP_DESC_NO_ROLE_LOGIN_FAIL;
    }

    public void buildAccountRepeatMessage() {
        this.success = false;
        this.messageCode = ResponseConstants.RSP_CODE_ACCOUNT_NAME_REPEAT_FAIL;
        this.info = ResponseConstants.RSP_INFO_ACCOUNT_NAME_REPEAT_FAIL;
        this.description = ResponseConstants.RSP_DESC_ACCOUNT_NAME_REPEAT_FAIL;
    }
    
    public void buildShopNameRepeatMessage() {
        this.success = false;
        this.messageCode = ResponseConstants.RSP_CODE_SHOP_NAME_REPEAT_FAIL;
        this.info = ResponseConstants.RSP_INFO_SHOP_NAME_REPEAT_FAIL;
        this.description = ResponseConstants.RSP_DESC_SHOP_NAME_REPEAT_FAIL;
    }
    
    public void buildShopCodeRepeatMessage() {
        this.success = false;
        this.messageCode = ResponseConstants.RSP_CODE_SHOP_CODE_REPEAT_FAIL;
        this.info = ResponseConstants.RSP_INFO_SHOP_CODE_REPEAT_FAIL;
        this.description = ResponseConstants.RSP_DESC_SHOP_CODE_REPEAT_FAIL;
    }
    
    public void buildUserCodeRepeatMessage() {
        this.success = false;
        this.messageCode = ResponseConstants.RSP_CODE_USER_CODE_REPEAT_FAIL;
        this.info = ResponseConstants.RSP_INFO_USER_CODE_REPEAT_FAIL;
        this.description = ResponseConstants.RSP_DESC_USER_CODE_REPEAT_FAIL;
    }
    
    
    public void buildAccountSelfDeleteMessage() {
        this.success = false;
        this.messageCode = ResponseConstants.RSP_CODE_ACCOUNT_DELETE_SELF_FAIL;
        this.info = ResponseConstants.RSP_INFO_ACCOUNT_DELETE_SELF_FAIL;
        this.description = ResponseConstants.RSP_DESC_ACCOUNT_DELETE_SELF_FAIL;
    }
    
    @Override
    public String toString() {
        return "ResponseMessage{" +
                "messageCode='" + messageCode + '\'' +
                ", info='" + info + '\'' +
                ", description='" + description + '\'' +
                ", success=" + success +
                ", Data=" + Data +
                '}';
    }
}
